﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Site
{
    public partial class AddUser : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (Session == null)
            {
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Your Session has expired, please log in again.')</SCRIPT>");
                return;
            }
            if (Session["userType"].ToString() == "admin" || Session["userType"].ToString() == "root")
            {
                SqlDataSource1.InsertCommand = "INSERT INTO Users (userID, userPass, userType, userHidden) VALUES('" + edtUser.Text + "', '" + edtPass.Text + "', " +  DropDownList1.Text + ", 'False')";
                SqlDataSource1.Insert();

                Response.Redirect("Default.aspx");
            }
            else
            {
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('You are not allowed to add users, please login with an account that has full root access')</SCRIPT>");
                //Response.Redirect("Default.aspx");
            }
        }
    }
}